<template>
    <el-dialog title="达人详情" width="760px" :visible.sync="show" append-to-body>
        <el-form label-width="120px"  ref="talent" :model="talent" class="submit_form">
            <el-form-item label="修改时间">{{talent.apply_time}}</el-form-item>
            <el-form-item label="认证照片">
                <el-image style="width: 100px; height: 100px"
                          :src="talent.verify_img"
                          :preview-src-list="[talent.verify_img]"
                          fit="contain"></el-image>
            </el-form-item>
            <el-form-item label="常住地区" prop="short_name">{{talent.short_name}}</el-form-item>
            <el-form-item label="认证状态" prop="status">
                <el-radio-group v-model="talent.status" size="medium">
                    <el-radio :label="-1" disabled>资料待完善</el-radio>
                    <el-radio :label="0" disabled>待认证</el-radio>
                    <el-radio :label="1">认证通过</el-radio>
                    <el-radio :label="2">认证不通过</el-radio>
                    <el-radio :label="3">冻结</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="认证达人" prop="intelligent" v-if="talent.status === 1">
                <el-radio-group v-model="talent.intelligent" size="medium">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="0">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="认证意见" prop="remark" v-if="talent.status === 2 || talent.status === 3">
                <el-input type="textarea" v-model="talent.remark"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">确定</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
    export default {
        name: "TalentVerifyDialog",
        data(){
            return{
                show:false,
                talent:{},
                submitting:false,
            }
        },
        watch: {
            talent: {
                deep: true, // obj深度监听
                handler: function (newValue) {
                    if (newValue.status === 1) {
                        this.talent.remark = '';
                    } else {
                        this.talent.intelligent = 0;
                    }
                }
            },
        },
        methods:{
            init(talent){
                this.talent = Object.assign({}, talent);
                this.show = true;
            },
            onSubmit(){
                let that = this;
                let status = this.talent.status;
                console.log(status);
                if((status === 2 || status === 3) && this.talent.remark === ''){
                    this.$message.info('请输入认证意见');
                    return;
                }
                this.submitting = true;
                this.post('/api/laifei/talent/auth',{
                    talent_id:this.talent.talent_id,
                    remark:this.talent.remark,
                    status: this.talent.status,
                    intelligent: this.talent.intelligent,
                }).then(result=>{
                    if(result.code === 0){
                        that.$message.success(result.msg);
                        that.show = false;
                        that.$emit('refresh');
                    } else {
                        that.$message.error(result.msg);
                    }
                    that.submitting = false;
                })
            },
        }
    }
</script>

<style scoped>

</style>
